#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
#include <QGLFunctions>
#include <QPoint>
#include <QTimer>
#include <QMatrix4x4>
#include <QMouseEvent>
#include <QWheelEvent>
#include <vector>
#include <string>

using namespace std;

//enum E_CLB_3D_TYPE = {CLB,IO};

struct s_line {
    float x0,y0,z0;
    float x1,y1,z1;
    float r,g,b;
};

class C_CLB_3D {

public:
    C_CLB_3D();
    C_CLB_3D(const char* name, int x, int y, int z);

    C_CLB_3D(const char* name, float x, float y, float z);
    
    void get_loc(float& x,float& y,float& z);
    void set_loc(float x,float y,float z);
    
    const char* getName(void);
    
    void setColor(float r,float g,float b);
    void getColor(float& r,float& g,float& b);

    void addFanout(unsigned int idx);
    bool getFanout(vector<unsigned int>& cellIdxs);

private:
    vector<unsigned int> _fanout;
    string _name;
    float _x,_y,_z;
    float _r,_g,_b;
};

class GLWidget : public QGLWidget, protected QGLFunctions
{
    Q_OBJECT
public:
    explicit GLWidget(QWidget *parent = 0);

    void initializeGL();
    void paintGL();
    void resizeGL(int w, int h);

    void mousePressEvent(QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent *e);
    void wheelEvent ( QWheelEvent *e);
    void keyPressEvent(QKeyEvent *e);
    void keyReleaseEvent(QKeyEvent *e);

    void drawcube(double x,double y,double layer,GLenum LN_Mode);
    void drawcube(double x,double y, double layer,GLenum LN_Mode,
        float r, float g, float b);
    
    void drawline(float x0,float y0, float z0,
        float x1,float y1, float z1,
        float r, float g, float b,float lineWidth=1.0);

private:
    QTimer timer;
    QMatrix4x4 projection;
    GLfloat rotationX;
    GLfloat rotationY;
    GLfloat rotationZ;
    GLfloat move;
    QPoint lastPos;

    GLfloat eyeX;
    GLfloat eyeY;
    GLfloat eyeZ;

    GLfloat moveX;
    GLfloat moveY;
    GLfloat moveZ;

};

#endif // GLWIDGET_H
